package cn.q3.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * 分页工具
 *
 * @param <T>
 */
public class PageUtil<T> {
    //当前页码
    private int pageNo=1;
    //总页数
    private  int pageAll=1;
    //每页数量
    private  int size=5;
    //总记录
    private int count=0;
    //携带的数据
    private List<T> datas   =new ArrayList<>();

    public PageUtil() {
   super();
    }

    public PageUtil(int pageNo, int size, int count) {
       setPageNo(pageNo);
       setSize(size);
       setCount(count);
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
      //设置控制阀
        if (pageNo<1){
            this.pageNo=1;
        }else {
            this.pageNo=pageNo;
        }
    }

    public int getPageAll() {
        return pageAll;
    }

    public void setPageAll(int pageAll) {
        this.pageAll = pageAll;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        if (size < 1) {
            this.size = 5;
        } else {
            this.size = size;
        }
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        if (count > 0) {
            this.pageAll = count % size == 0 ? count / size : count / size + 1;
            this.count = count;
        }
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }
}
